﻿<%@ Page Title="" Language="C#" MasterPageFile="~/UFSSMaster.Master" AutoEventWireup="true" CodeBehind="userfile.aspx.cs" Inherits="UFSSWebApp.userfile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageName" runat="server">
    <%
    try
    {
        UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient();
        UFSSWebApp.UFSSservicereference.UserCreds uc = new UFSSWebApp.UFSSservicereference.UserCreds();
        UFSSWebApp.UFSSservicereference.UFSSFile file;
        uc = (UFSSWebApp.UFSSservicereference.UserCreds)Session["usercreds"];
        
        if (Request.QueryString["id"] == null)
        {
            file = (UFSSWebApp.UFSSservicereference.UFSSFile)Session["fileinfo"];
        }
        else
        {
            try
            {
                file = ussc.getFileInfo(uc, Int32.Parse(Request.QueryString["id"]));
            }
            catch
            {
                file = null;
            }

            int perindex = file.filename.LastIndexOf('.');
            string filename = file.filename.Substring(0, perindex);
            Response.Write(filename);
        }
    }
    catch
    {
        //Response.Redirect("~/profile.aspx");
    }
 %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Body" runat="server">
    <div class="Box" style="width:500px">
        <span class="subheading"><% 
                                     try
                                     {
                                         UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient();
                                         UFSSWebApp.UFSSservicereference.UserCreds uc = new UFSSWebApp.UFSSservicereference.UserCreds();
                                         UFSSWebApp.UFSSservicereference.UFSSFile file;
                                         uc = (UFSSWebApp.UFSSservicereference.UserCreds)Session["usercreds"];
                                         
                                         if (Request.QueryString["id"] == null)
                                         {
                                             file = (UFSSWebApp.UFSSservicereference.UFSSFile)Session["fileinfo"];
                                         }
                                         else
                                         {
                                             try
                                             {
                                                 file = ussc.getFileInfo(uc, Int32.Parse(Request.QueryString["id"]));
                                             }
                                             catch
                                             {
                                                 file = null;
                                             }
                                         }
                                         
                                         int perindex = file.filename.LastIndexOf('.');
                                         string filename = file.filename.Substring(0, perindex);
                                         Response.Write(filename);
                                     }
                                     catch
                                     {
                                         //Response.Redirect("~/profile.aspx");
                                     }
                                     %> - Information</span><hr />
        <table>
            <tbody>
                <tr>
                    <td>File Owner: </td>
                    <td></td>
                    <td><asp:LinkButton ID="lbtnOwner" runat="server" onclick="lbtnOwner_Click">
                    <%
                        try
                        {
                            UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient();
                            UFSSWebApp.UFSSservicereference.UserCreds uc = new UFSSWebApp.UFSSservicereference.UserCreds();
                            UFSSWebApp.UFSSservicereference.UFSSFile file;
                            uc = (UFSSWebApp.UFSSservicereference.UserCreds)Session["usercreds"];
                            
                            if (Request.QueryString["id"] == null)
                            {
                                file = (UFSSWebApp.UFSSservicereference.UFSSFile)Session["fileinfo"];
                            }
                            else
                            {
                                try
                                {
                                    file = ussc.getFileInfo(uc, Int32.Parse(Request.QueryString["id"]));
                                }
                                catch
                                {
                                    file = null;
                                }
                            }

                            Response.Write(ussc.getUserName(file.ownerid));
                            //Response.Write(Session["user"].ToString());
                        }
                        catch
                        {
                            //Response.Redirect("~/home.aspx");
                        }
                         %></asp:LinkButton></td>
                </tr>
                <tr><td></td></tr>
                <tr>
                    <td>In Subscription: </td>
                    <td></td>
                    <td><asp:LinkButton ID="lbtnSub" runat="server" onclick="lbtnSub_Click">
                    <%
                        try
                        {
                            UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSWebApp.UFSSservicereference.UFSSserviceSoapClient();
                            UFSSWebApp.UFSSservicereference.UserCreds uc = new UFSSWebApp.UFSSservicereference.UserCreds();
                            UFSSWebApp.UFSSservicereference.UFSSFile file;
                            uc = (UFSSWebApp.UFSSservicereference.UserCreds)Session["usercreds"];
                            
                            if (Request.QueryString["id"] == null)
                            {
                                file = (UFSSWebApp.UFSSservicereference.UFSSFile)Session["fileinfo"];
                            }
                            else
                            {
                                try
                                {
                                    file = ussc.getFileInfo(uc, Int32.Parse(Request.QueryString["id"]));
                                }
                                catch
                                {
                                    file = null;
                                }
                            }
                            
                            if (!file.subname.Equals(null))
                                Response.Write(file.subname.ToString());
                            else
                                Response.Write("Not in a subscription");
                        }
                        catch
                        {
                            Response.Write("Not in a subscription");
                            //Response.Redirect("~/home.aspx");
                        }
                         %>
                    </asp:LinkButton></td>
                </tr>
                <tr><td></td></tr>
                <tr>
                    <td>Download Count: </td>
                    <td></td>
                    <td><asp:Label ID="lblDLCount" runat="server" Text=""></asp:Label></td>
                </tr>
                <tr><td></td></tr>
                <tr>
                    <td>File Size: </td>
                    <td></td>
                    <td><asp:Label ID="lblFileSize" runat="server" Text=""></asp:Label></td>
                </tr>
                <tr><td></td></tr>
                <tr>
                    <td>Date Uploaded</td>
                    <td></td>
                    <td><asp:Label ID="lblUploaded" runat="server" Text=""></asp:Label></td>
                </tr>
                <tr><td></td><td><asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label></td></tr>
                <tr>
                    <td><asp:Button ID="btnDownload" runat="server" Text="Download File" 
                            onclick="btnDownload_Click" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</asp:Content>
